package com.laicunba.event.listener;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.laicunba.event.PaySuccessEvent;
import com.laicunba.pojo.FinancingTargetBidDO;
import com.laicunba.pojo.RegistryDO;
import com.laicunba.service.RegistryService;
import com.laicunba.service.UserService;
import com.laicunba.service.activity.FriendBidActivityService;

@Component
public class LuckyDrawCountListener implements ApplicationListener<PaySuccessEvent> {
	private static final Logger LOG = Logger.getLogger(LuckyDrawCountListener.class);

	@Autowired
	private UserService userService;
	@Autowired
	private RegistryService registryService;

	@Autowired
	private FriendBidActivityService friendBidActivityService;

	@Override
	public void onApplicationEvent(PaySuccessEvent event) {
//		FinancingTargetBidDO bidDO = (FinancingTargetBidDO) event.getSource();
//		if ("CPB".equalsIgnoreCase(bidDO.getType())) {
//			String countKey = "u." + bidDO.getBidUserId() + ".lucky-draw.count";
//			RegistryDO registryDO = registryService.get(RegistryDO.class, countKey);
//			if (registryDO != null && Integer.parseInt(registryDO.getVal()) >= 0) {
//				registryService.update(countKey, String.valueOf(Integer.parseInt(registryDO.getVal()) + 1));
//				LOG.info(String.format("活动期间，用户[%s]购买成功后,增加转盘活动抽奖次数为[%s]", bidDO.getBidUserId(), Integer.parseInt(registryDO.getVal()) + 1));
//			} else {
//				registryService.create(countKey, "1");
//				LOG.info(String.format("活动期间，用户[%s]首次购买成功,设置转盘活动抽奖次数为1", bidDO.getBidUserId(), 1));
//			}
//		}
	}

}
